#include <QtEndian>

#include "include/network/SocketData.h"

SocketData::SocketData(QTcpSocket *socket)
    : socket(socket), dataBuff(NULL) {
    sizeBuffRead = dataBuffRead = 0;
}

SocketData::~SocketData() {
    if (dataBuff != NULL) {
        delete dataBuff;
    }
}

quint32 SocketData::getSize() {
    return qFromBigEndian(*(quint32 *) sizeBuff);
}

void SocketData::prepareDataBuff() {
    if (dataBuff != NULL) {
        delete dataBuff;
    }
    dataBuff = new uchar[getSize()];
}
